home *** CD-ROM | disk | FTP | other *** search
- /*
- File: PartUtils.cpp
-
- Contains: Part utility functions & classes
-
- Written by: PartMaker
-
- Change History (most recent first):
-
- <4> 4/14/95 JS Updated for Developer Release 2
- <2> 3/8/95 JS Updated to b1c13/c14
- <1> 2/2/95 RA first checked in
- <0> PartMaker source by E, Soldan, T. Çelik, J. Alfke, R. Adkins, J. Schalk
- */
-
- #ifndef _ALTPOINT_
- #include <AltPoint.h> /* Must come before other OpenDoc includes */
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _ODTYPES_
- #include <ODTypes.h> // MUST BE BEFORE TOOLBOX INCLUDES
- #endif
-
- #ifndef _CPPICTPART_
- #include "CPPictPart.h"
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef _PARTUTILS_
- #include "PartUtils.h"
- #endif
-
-
- #ifdef applec
- #pragma segment PictPart
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // MyDialogFilter
- //----------------------------------------------------------------------------------------
-
- pascal Boolean MyDialogFilter(DialogPtr dialog, EventRecord* event, short* itemHit)
- {
- ODBoolean handled = kODFalse;
-
- if (event->what == nullEvent ||
- event->what == updateEvt && (WindowPtr) event->message != dialog ||
- event->what == activateEvt && (WindowPtr) event->message != dialog)
- {
- Environment *ev = somGetGlobalEnvironment();
- gSession->GetDispatcher(ev)->Dispatch(ev,(ODEventData*)event);
- }
- else if ((event->what == keyDown) || (event->what == autoKey))
- {
- #define kMyButtonDelay 8
- long waitTicks;
- short itemKind;
- Handle itemHandle;
- Rect itemRect;
- char key = (char)(event->message & charCodeMask);
- const char kReturnKey = 13;
- const char kEnterKey = 3;
- const char kEscKey = 27;
-
- switch(key)
- {
- case kReturnKey:
- case kEnterKey:
- *itemHit = ok;
- ::GetDialogItem(dialog, ok, &itemKind, &itemHandle, &itemRect);
- ::HiliteControl((ControlHandle)itemHandle, kInButtonControlPart);
- ::Delay(kMyButtonDelay, &waitTicks);/* wait about 8 ticks */
- HiliteControl((ControlHandle)itemHandle, kODFalse);
- handled = kODTrue;
- break;
- case kEscKey:
- *itemHit = cancel;
- ::GetDialogItem(dialog, cancel, &itemKind, &itemHandle, &itemRect);
- ::HiliteControl((ControlHandle)itemHandle, kInButtonControlPart);
- ::Delay(kMyButtonDelay,&waitTicks);
- HiliteControl((ControlHandle)itemHandle, kODFalse);
- handled = kODTrue;
- break;
- }
- }
-
- return handled;
- }
-
- //----------------------------------------------------------------------------------------
- // GetWindowPoint
- //----------------------------------------------------------------------------------------
-
- void GetWindowPoint(ODWindow *w, Environment *ev,
- Point globalPoint,
- ODPoint *localPoint)
- {
- GrafPtr curPort;
- ::GetPort(&curPort);
- ::SetPort(w->GetPlatformWindow(ev));
- ::SetOrigin(0,0);
- ::GlobalToLocal(&globalPoint);
- ::SetPort(curPort);
- *localPoint = globalPoint;
- }
-